<template>
  <div>
    <crumb isShowBack/>
    <div class="course-study main-contianer2">
      <div class="right-content">
        <el-form style="margin: 20px 20px 0 20px;">
          <el-form-item label="选择日期：">
            <el-date-picker v-model="date" type="datetimerange" range-separator="至" start-placeholder="开始日期" end-placeholder="结束日期" value-format="yyyy-MM-dd HH:mm:ss" @change="getHistoryOnlineLessonList"></el-date-picker>
          </el-form-item>
        </el-form>
        <div class="online-box" v-for="item in list" :key="item.id">
          <div class="online-left">
            <div class="online-title">课题：{{item.resourceLessonName}}</div>
            <div class="online-item">课程：{{item.lessonProject}}</div>
            <div class="online-item">主讲：{{item.teacherName}}</div>
            <div class="online-item">班级：{{item.classNames}}</div>
            <div class="online-item">时间：{{formatDate(item.onlineLessonStartTime)}} - {{formatDate(item.onlineLessonEndTime)}}</div>
          </div>
          <div class="online-right">
            <div class="online-tag2">已完成</div>
            <el-button type="primary" @click="getHistoryOnlineLessonStatInfo(item)">查看数据</el-button>
          </div>
        </div>
      </div>
      <div class="left-list">
        <ul class="tabs flex-row">
          <li :class="['tab', { 'active': tabId == 1 }]" @click="changeTab(1)">交流</li>
          <li :class="['tab', { 'active': tabId == 2 }]" @click="changeTab(2)">活动</li>
          <li :class="['tab', { 'active': tabId == 3 }]" @click="changeTab(3)">资源</li>
          <li :class="['tab', { 'active': tabId == 4 }]" @click="changeTab(4)">笔记</li>
        </ul>
        <div v-if="tabId == 1">
          <div class="online-actCon" style="height: 815px;">
            <div class="chat-box left" v-for="(item, index) in msgList" :key="index">
              <img :src="item.headUrl" class="chat-logo" alt="">
              <div class="chat-con">
                <div class="chat-name">{{item.name}}</div>
                <div class="chat-cont">{{item.interchangeContent}}</div>
              </div>
            </div>
          </div>
          <div class="chat-doBox">
            <div class="chat-doCon">
              <el-input class="chat-input" placeholder="请输入您的发言" v-model="msg"></el-input>
              <!--图片功能-->
              <!--el-upload-->
              <!--<div class="chat-uploadImg">-->
              <!--<i class="el-icon-picture"></i>-->
              <!--</div>-->
            </div>
            <el-button type="primary" @click="addExchange">发送</el-button>
          </div>
        </div>
        <div v-if="tabId == 2">
          <div class="online-actCon">
            <div class="online-acts" v-for="(item, index) in actList" :key="index">
              <div class="online-actBox">
                <div class="online-actKey">{{item.activityNoteName}}</div>
                <div class="online-actVal">
                  <el-button type="text" icon="el-icon-circle-check">{{item.activityInNum}}/{{item.activityNum}}</el-button>
                  <el-button type="text" icon="el-icon-time">{{item.noteTime}}</el-button>
                </div>
              </div>
              <div class="online-btnBox">
                <el-button type="primary" size="mini" plain @click="handleCommentView(item)" v-if="item.type === '4'">评分</el-button>
                <el-button type="primary" size="mini" plain @click="handleActView(item)">查看</el-button>
              </div>
            </div>
          </div>
        </div>
        <div v-if="tabId == 3">
          <div class="online-actCon">
            <div class="online-acts" @click="handleFile(index)" v-for="(item, index) in fileList" :key="index">
              <div class="online-actBox">
                <div class="online-actKey">{{item.fileName}}</div>
                <div class="online-actVal">
                  <el-button type="text" icon="el-icon-s-custom">{{item.name}}</el-button>
                  <el-button type="text" icon="el-icon-s-order">{{item.fileType}}M</el-button>
                </div>
              </div>
            </div>
          </div>
          <el-button type="primary" style="width: 100%;">上传资源</el-button>
        </div>
        <div v-if="tabId == 4">
          <div class="online-note" v-if="!noteState">{{note}}</div>
          <el-input type="textarea" class="online-note" placeholder="请输入笔记内容" v-model="note" v-else></el-input>
          <div class="online-notes">
            <el-button type="primary" icon="el-icon-edit" class="fr" v-if="!noteState" @click="noteState=true">记笔记</el-button>
            <el-button type="primary" icon="el-icon-edit" class="fr" v-else @click="saveOnlineLessonStuNote">保存</el-button>
          </div>
        </div>
      </div>
    </div>
  </div>
</template>

<script>
import { getHistoryOnlineLessonList, exchangeList, addExchange, activityList, getOnlineLessonStuNote, saveOnlineLessonStuNote } from '@/api/student/lesson/classroom'
import { getOnlineResource } from '@/api/teacher/onlineCourse'
export default {
  data () {
    return {
      date: undefined,
      onlineLesson: undefined,
      info: undefined,
      list: [],
      tabId: 1,
      // 交流
      msg: '',
      msgList: [],
      // 活动
      actList: [],
      // 资源
      fileList: [],
      // 笔记
      noteState: false,
      note: '',
      onlineLessonId: undefined
    }
  },
  methods: {
    async getHistoryOnlineLessonList () {
      const data = {
        startDate: this.date[0],
        endDate: this.date[1]
      }
      const res = await getHistoryOnlineLessonList(data)
      if (res.code === '200') {
        this.list = res.list
      }
    },
    getHistoryOnlineLessonStatInfo (item) {
      this.onlineLessonId = item.onlineLessonId
      this.msg = this.note = ''
      this.msgList = this.fileList = []
      this.exchangeList()
      this.activityList()
      this.getOnlineResource()
      this.getOnlineLessonStuNote()
    },
    changeTab (tab) {
      this.tabId = tab
    },
    // 获取消息列表
    async exchangeList () {
      const res = await exchangeList({ onlineLessonId: this.onlineLessonId })
      this.msgList = res.data.reverse()
    },
    // 发送消息
    async addExchange () {
      const data = {
        onlineLessonId: this.onlineLessonId,
        interchangeContent: this.msg
      }
      const res = await addExchange(data)
      if (res.code === '200') {
        this.msg = ''
        this.exchangeList()
      }
    },
    // 获取活动列表
    async activityList () {
      const res = await activityList({ onlineLessonId: this.onlineLessonId })
      if (res.code === '200') {
        this.actList = res.data
      }
    },
    // 获取资源
    async getOnlineResource () {
      const res = await getOnlineResource({ onlineLessonId: this.onlineLessonId })
      if (res.code === '200') {
        this.fileList = res.data
      }
    },
    // 获取笔记
    async getOnlineLessonStuNote () {
      const res = await getOnlineLessonStuNote({ onlineLessonId: this.onlineLessonId })
      if (res.code === '200') {
        this.note = res.data.noteStr
      }
    },
    // 保存笔记
    async saveOnlineLessonStuNote () {
      const data = {
        onlineLessonId: this.onlineLessonId,
        note: this.note
      }
      const res = await saveOnlineLessonStuNote(data)
      if (res.code === '200') {
        this.$message.success('笔记保存成功')
        this.note = ''
        this.noteState = false
        this.getOnlineLessonStuNote()
      }
    },
    formatDate (nS) {
      return new Date(parseInt(nS)).toLocaleString().replace(/:\d{1,2}$/, ' ')
    }
  },
  mounted () {
  }
}
</script>

<style scoped lang="scss" rel="stylesheet/scss">
  .course-study {
    height: 937px;
    width: 1200px;
    margin: 0 auto;
    .left-list {
      width: 590px;
      height: 100%;
    }
    .right-content {
      width: 590px;
      height: 100%;
      background: #fff;
      border: 1px solid rgba(229, 229, 229, 1);
      border-radius: 5px;
      overflow-y: scroll;
    }
  }
  .tabs {
    width: 100%;
    height: 40px;
    margin-top: 20px;
    .tab {
      width: 25%;
      text-align: center;
      font-size: 20px;
      height: 40px;
      line-height: 40px;
      color: #101d37;
      cursor: pointer;
      &.active {
        color: #009cf6;
        position: relative;
        &::before {
          content: "";
          width: 52px;
          height: 3px;
          background: rgba(0, 156, 246, 1);
          border-radius: 3px;
          position: absolute;
          bottom: 0;
          left: 50%;
          transform: translateX(-50%);
        }
      }
    }
  }
</style>
